//
//  KHHStoryCollectionViewCell.m
//  Travel
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "KHHStoryCollectionViewCell.h"
#import "KHHStoryItemCollectionViewCell.h"

@interface KHHStoryCollectionViewCell ()

@property (nonatomic, retain)UICollectionViewFlowLayout *layout;
@end

@implementation KHHStoryCollectionViewCell

//初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

//创建
- (void)createView
{
    self.layout = [[UICollectionViewFlowLayout alloc]init];
    
#warning 问题1:tableviewcell中 init创建布局为系统默认(320, 530) 设置frame时取window宽度
    //创建collectionView
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.layout];
    //滑动视图距离根视图内容边界
    self.collectionView.contentInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.collectionView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    [self.contentView addSubview:self.collectionView];
    
    //collectionView 注册cell
    [self.collectionView registerClass:[KHHStoryItemCollectionViewCell class] forCellWithReuseIdentifier:@"StoryItemitem"];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
//    // 夜间模式
//    
//    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"isNight"]) {
//        self.collectionView.backgroundColor = [UIColor colorWithRed:0.28 green:0.28 blue:0.28 alpha:1];
//        [self.collectionView reloadData];
//    }else
//    {
//        self.collectionView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
//        [self.collectionView reloadData];
//        
//    }
    
    self.layout.itemSize = CGSizeMake(( [UIScreen mainScreen].bounds.size.width - 30) / 2, 240);
    //列间距
    self.layout.minimumLineSpacing = 10;
    //行间距
    self.layout.minimumInteritemSpacing = 10;
    
    self.collectionView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 510);
    
}

- (void)setDelegate:(id<UICollectionViewDelegate>)delegate
{
    self.collectionView.delegate = delegate;
}
- (void)setDataSource:(id<UICollectionViewDataSource>)dataSource
{
    self.collectionView.dataSource = dataSource;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
